home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.db.awt;
-
- import java.util.BitSet;
- import symantec.itools.db.pro.MultiView;
- import symantec.itools.db.pro.RelationView;
- import symantec.itools.db.pro.RelationViewMetaData;
- import symjava.sql.SQLException;
-
- public class DbaDataStore implements DbDataStore, MetaTable, DbDataUpdater {
- Position position;
- RelationView master;
- RelationView relView;
- MultiView multiView;
- DbDataSource source;
- DbaDataLink link;
- int coltoshow;
- RelationViewMetaData meta;
- public static final int MAX_DISPLAY_SIZE = 60;
- int[] rowMapping;
- BitSet createdRows;
- int lastValidIndex;
- int lastIndex_;
- int lastRowRetrieved;
- boolean obtainedAllRows = false;
- static final int START_SIZE = 100;
- static final int INC_SIZE = 100;
-
- public DbaDataStore(RelationView var1, RelationView var2) throws SQLException {
- if (var2 != null) {
- this.master = var2;
- }
-
- this.relView = var1;
- this.multiView = var1.getMultiView();
- this.meta = this.relView.getMetaData();
- this.position = new Position(var1);
- }
-
- void resetRows() throws SQLException {
- int var1 = this.position.getIgnoreCount();
- if (var1 <= 0) {
- this.initRowMapping();
- this.source.view.clear();
- }
- }
-
- void notifyRecordChange() throws SQLException {
- int var1 = this.position.getIgnoreCount();
- if (var1 <= 0) {
- int var2 = this.position.get();
- if (this.relView.getCurrentRecordState() == 102) {
- this.source.view.scrollUpDownAbsolute(var2 - 1);
- }
-
- this.source.view.setFocusToRow(var2);
- }
- }
-
- public void fetchMode(boolean var1) {
- this.setManRowChangeFlag(var1);
- }
-
- public boolean manualRowChangeFlag() {
- return this.position.getNotificationMode();
- }
-
- private void setManRowChangeFlag(boolean var1) {
- try {
- this.position.setNotificationMode(var1);
- } catch (SQLException var2) {
- }
- }
-
- public void setCurrentRow(int var1) throws TypeNotSupported {
- ++var1;
-
- try {
- int var2 = this.translateRow(var1);
- this.position.set(var2);
- } catch (Exception var3) {
- throw new TypeNotSupported(((Throwable)var3).getMessage());
- }
- }
-
- public boolean isCurrentRow(int var1) {
- try {
- int var2 = this.translateRow(var1);
- return var2 == this.position.get();
- } catch (Exception var3) {
- return false;
- }
- }
-
- public void setDbDataSource(DbDataSource var1) {
- if (this.source == null) {
- this.source = var1;
- this.initRowMapping();
- this.link = new DbaDataLink(this);
- this.position.ignoreNotification(true);
-
- try {
- this.relView.bindRecordSet(this.link);
- this.relView.bindCurrentRecord(this.link);
- } catch (SQLException var2) {
- }
-
- this.position.ignoreNotification(false);
- }
- }
-
- public boolean supportsCaching() {
- return true;
- }
-
- public int validDataRowRange(int var1, int var2) throws DataNotAvailable {
- ++var1;
- var2 += 2;
- int var3 = Math.max(1, var1);
-
- try {
- this.setManRowChangeFlag(true);
-
- while(var3 <= var2) {
- this.translateRow(var3);
- ++var3;
- }
- } catch (DataNotAvailable var8) {
- } finally {
- this.setManRowChangeFlag(false);
- }
-
- if (var3 == var1) {
- throw new DataNotAvailable("top is greater than last row in database");
- } else {
- return var3 - 1;
- }
- }
-
- public Data getData(int var1, int var2) throws DataNotAvailable {
- ++var1;
- Object var3 = null;
-
- try {
- this.setManRowChangeFlag(true);
- int var6 = this.translateRow(var1);
- boolean var7 = this.position.set(var6);
- if (!var7) {
- throw new DataNotAvailable("Could not move to row " + var1);
- }
-
- String var8 = this.relView.getStringValue(var2);
- if (var8 == null) {
- var8 = "";
- }
-
- var14 = new ImageStringData(this.source, var8);
- } catch (Exception var11) {
- throw new DataNotAvailable(((Throwable)var11).getMessage());
- } finally {
- this.setManRowChangeFlag(false);
- }
-
- return var14;
- }
-
- public void update(int var1, int var2, Data var3) throws TypeNotSupported {
- ++var1;
-
- try {
- this.setManRowChangeFlag(true);
- int var6 = this.translateRow(var1);
- this.position.set(var6);
- this.relView.setValueFromString(var2, var3.toString());
- } catch (Exception var9) {
- throw new TypeNotSupported(((Throwable)var9).getMessage());
- } finally {
- this.setManRowChangeFlag(false);
- }
-
- }
-
- public int rowState(int var1) {
- ++var1;
- byte var2 = 0;
-
- try {
- this.setManRowChangeFlag(true);
- int var5 = this.translateRow(var1);
- this.position.set(var5);
- byte var6 = this.relView.getCurrentRecordState();
- switch (var6) {
- case 100:
- var2 = 1;
- break;
- case 101:
- var2 = 3;
- break;
- case 102:
- var2 = 0;
- break;
- case 103:
- var2 = 2;
- }
- } catch (Exception var9) {
- ((Throwable)var9).printStackTrace();
- } finally {
- this.setManRowChangeFlag(false);
- }
-
- return var2;
- }
-
- public void clear() {
- this.initRowMapping();
- }
-
- public void refresh() {
- try {
- this.relView.restartMultiView();
- } catch (SQLException var1) {
- }
- }
-
- public void undoRow(int var1) throws TypeNotSupported {
- ++var1;
-
- try {
- this.position.ignoreNotification(true);
- this.relView.undoRecord();
- } catch (SQLException var7) {
- throw new TypeNotSupported(((Throwable)var7).getMessage());
- } finally {
- this.position.ignoreNotification(false);
- }
-
- }
-
- public int rowsRetrieved() {
- return this.lastIndex_;
- }
-
- public int fetchAllRows() {
- int var1 = 1;
-
- try {
- this.setManRowChangeFlag(true);
-
- while(true) {
- this.translateRow(var1);
- ++var1;
- }
- } catch (DataNotAvailable var6) {
- } finally {
- this.setManRowChangeFlag(false);
- }
-
- return var1 - 1;
- }
-
- public void undeleteRow(int var1) throws TypeNotSupported {
- try {
- ++var1;
- this.position.ignoreNotification(true);
- this.relView.undoRecord();
- } catch (SQLException var7) {
- throw new TypeNotSupported(((Throwable)var7).getMessage());
- } finally {
- this.position.ignoreNotification(false);
- }
-
- }
-
- public void deleteRow(int var1) throws TypeNotSupported {
- try {
- ++var1;
- this.position.ignoreNotification(true);
- this.relView.deleteRecord();
- } catch (SQLException var7) {
- throw new TypeNotSupported(((Throwable)var7).getMessage());
- } finally {
- this.position.ignoreNotification(false);
- }
-
- }
-
- public void save() throws TypeNotSupported {
- try {
- this.relView.saveMultiView();
- } catch (SQLException var2) {
- throw new TypeNotSupported(((Throwable)var2).getMessage());
- }
- }
-
- public void getNewRecord() throws TypeNotSupported {
- try {
- this.relView.getNewRecord();
- } catch (SQLException var2) {
- throw new TypeNotSupported(((Throwable)var2).getMessage());
- }
- }
-
- public void insertRow(int var1) throws TypeNotSupported {
- this.appendRow();
- }
-
- public int appendRow() throws TypeNotSupported {
- this.getNewRecord();
- return 0;
- }
-
- public void setColtoShow(int var1) {
- this.coltoshow = var1;
- }
-
- public void setupGrid(Grid var1) {
- try {
- var1.setAutoRedraw(false);
- int var2 = this.coltoshow;
- if (this.coltoshow == 0 || this.meta.getColumnCount() <= this.coltoshow) {
- var2 = this.meta.getColumnCount();
- }
-
- var1.createColumns(var2);
- var1.setRowLabelHeadingStyle(0);
-
- for(int var3 = 1; var3 <= var2; ++var3) {
- int var4 = this.meta.getColumnDisplaySize(var3);
- var4 = Math.min(0, var4);
- var4 = Math.max(0, 60);
- var1.setHeading(this.meta.getColumnLabel(var3), var3, Math.min(var4, 10));
- this.setupColumn(var1, var3);
- }
-
- var1.setAutoRedraw(true);
- } catch (SQLException var5) {
- }
- }
-
- public void setDataSource(DataSource var1) {
- }
-
- public boolean isDataEditable(int var1, int var2) throws DataNotAvailable {
- boolean var7;
- try {
- ++var1;
- this.setManRowChangeFlag(true);
- int var5 = this.translateRow(var1);
- boolean var6 = this.position.set(var5);
- if (!var6) {
- return true;
- }
-
- var7 = this.meta.isWritable(var2) && this.relView.isCurrentRecordWritable();
- } catch (SQLException var10) {
- throw new DataNotAvailable(((Throwable)var10).getMessage());
- } finally {
- this.setManRowChangeFlag(false);
- }
-
- return var7;
- }
-
- public Data[] arrangeForViewing(Data[] var1) {
- return var1;
- }
-
- public void setupColumn(Grid var1, int var2) {
- try {
- int var3 = this.meta.getColumnType(var2);
- switch (var3) {
- case -7:
- case -4:
- case -3:
- case -2:
- case -1:
- case 0:
- case 1:
- case 12:
- case 91:
- case 92:
- case 93:
- case 1111:
- default:
- var1.setColumnAlignment(var2, 0);
- break;
- case -6:
- case -5:
- case 2:
- case 4:
- case 5:
- case 6:
- case 7:
- case 8:
- var1.setColumnAlignment(var2, 2);
- }
-
- if (this.meta.isCurrency(var2)) {
- var1.setColumnAlignment(var2, 2);
- }
-
- if (!this.meta.isWritable(var2)) {
- var1.setColEditable(var2, false);
- return;
- }
- } catch (SQLException var4) {
- var1.setColumnAlignment(var2, 0);
- }
-
- }
-
- private void initRowMapping() {
- this.rowMapping = new int[100];
- this.lastValidIndex = 99;
- this.lastRowRetrieved = 0;
- this.lastIndex_ = 0;
- this.obtainedAllRows = false;
- this.createdRows = new BitSet();
- }
-
- void printMap() {
- System.out.println("Row mappings - size=" + this.lastValidIndex + "\n\tlastIndex=" + this.lastIndex_ + " lastRow=" + this.lastRowRetrieved);
-
- for(int var1 = 0; var1 <= this.lastIndex_; ++var1) {
- System.out.println("\trow " + var1 + " -> " + this.rowMapping[var1]);
- }
-
- }
-
- private int translateRow(int var1) throws DataNotAvailable {
- try {
- while(this.lastIndex_ < var1) {
- if (this.createdRows.get(this.lastRowRetrieved + 1)) {
- ++this.lastRowRetrieved;
- } else {
- boolean var2 = this.position.set(this.lastRowRetrieved + 1);
- if (!var2) {
- this.obtainedAllRows = true;
- throw new DataNotAvailable("Ran out of rows to fetch at row=" + (this.lastRowRetrieved + 1));
- }
-
- this.lastRowRetrieved = this.relView.getCurrentRecordNumber();
- ++this.lastIndex_;
- this.growMap();
- this.rowMapping[this.lastIndex_] = this.lastRowRetrieved;
- }
- }
-
- return this.rowMapping[var1];
- } catch (SQLException var4) {
- throw new DataNotAvailable(((Throwable)var4).getMessage());
- }
- }
-
- private int insertRowIntoMap(int var1) throws DataNotAvailable {
- try {
- this.translateRow(var1);
- this.relView.getNewRecord();
- int var2 = this.relView.getCurrentRecordNumber();
- this.createdRows.set(var2);
- this.growMap();
- int var3 = this.lastIndex_ + 1 - var1;
- System.arraycopy(this.rowMapping, var1, this.rowMapping, var1 + 1, var3);
- ++this.lastIndex_;
- this.rowMapping[var1] = var2;
- return var2;
- } catch (Exception var4) {
- throw new DataNotAvailable(((Throwable)var4).getMessage());
- }
- }
-
- private int appendRowIntoMap() throws DataNotAvailable {
- try {
- while(!this.obtainedAllRows) {
- this.translateRow(this.lastRowRetrieved + 1);
- }
- } catch (DataNotAvailable var3) {
- if (!this.obtainedAllRows) {
- throw var3;
- }
- }
-
- try {
- this.relView.getNewRecord();
- this.growMap();
- this.lastRowRetrieved = this.relView.getCurrentRecordNumber();
- this.createdRows.set(this.lastRowRetrieved);
- this.rowMapping[++this.lastIndex_] = this.lastRowRetrieved;
- } catch (SQLException var2) {
- throw new DataNotAvailable("Could not create new record");
- }
-
- return this.lastIndex_;
- }
-
- final void growMap() {
- if (this.lastIndex_ == this.lastValidIndex - 1) {
- int[] var1 = new int[this.lastValidIndex += 100];
- System.arraycopy(this.rowMapping, 0, var1, 0, this.rowMapping.length);
- this.rowMapping = var1;
- }
-
- }
-
- public Object getSynchronizationObject() {
- return this.multiView;
- }
- }
-